package com.jeesite.modules.dataScreen.service;

import cn.hutool.core.collection.CollUtil;
import com.jeesite.modules.dataScreen.web.vo.CoreBusinessRVO;
import com.jeesite.modules.dataScreen.web.vo.IndustryIndexVo;
import com.jeesite.modules.dataScreen.web.vo.transportationcore.InfrastructureVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;


@Service
public class TransportationCoreService {

    //公路管理
    private static final String[] INFRASTRUCTURE_GL = new String[]{"全市“十四五”规划高速公路通车里程完成率", "在建项目数量", "普通国省道新改建项目完工里程百分比", "农村公路当年计划项目完工里程百分比",
            "前一年修复及养护里程", "普通国省道预防性养护项目在建里程", "农村公路安防工程新安装完成百分比", "高速公路实时车流量/辆", "高速路网平均车速", "高速阻断事件抢通率", "上月日均交通流量", "普通国省道阻断事件抢通率"};
    //民航
    private static final String[] INFRASTRUCTURE_MH = new String[]{"全市运输机场航站楼停机位总个数", "全市运输机场跑道总条数", "全市运输机场旅客吞吐能力", "全市运输机场货邮吞吐能力", "民航当年在建项目投资完成率"
    };
    //港航
    private static final String[] INFRASTRUCTURE_GH = new String[]{"危险货物港口作业量", "危险货物港口作业货种预警", "船舶水污染物接收转运率", "在建港口码头当年计划完成投资", "在建港口码头当年投资完成进度", "在建航道整治工程项目当年投资完成进度", "在建航运（电）枢纽项目当年投资完成进度", "高等级航道占比", "航标维护正常率"};
    //邮政
    private static final String[] INFRASTRUCTURE_YZ = new String[]{"邮政普遍服务营业场所名录","重庆市许可快递企业","邮政行业寄递业务量","快递业务量","同城业务量","异地业务量","国际/港澳台快递业务量及同比增速"};
    //铁路
    private static final String[] INFRASTRUCTURE_TL = new String[]{"当年铁路重点工程项目总投资","当年铁路重点工程项目计划投资","当年铁路重点工程项目里程","铁路投资完成率"
            ,"铁路运营里程","高速铁路里程","普速铁路里程","去年铁路路网密度","轨道运营线路条数","轨道交通列车数量","轨道运营车站数","轨道换乘车站数"};


    //客运服务
    private static final String[] YSFW_KYFW = new String[]{
            "中心城区巡游出租车实载率","中心城区巡游出租车行业稳定度","中心城区网约出租车行业饱和度",
            "城市轨道交通客运分担率","轨道线网运营里程","轨道线网客流总量","轨道列车正点率",
            "中心城区公交运营车辆数","中心城区昨日公交客流量",
            "全市当日客运车辆数","全市联网售票班线客运当日累计客流量",
            "三峡游乘客数预警指数","三峡游乘客数预警指标",
            "一二类和重点三类维修企业数量","全市驾驶培训机构数量","驾校学员存量数据",
            "旅客发送量","旅客周转量","旅客吞吐量","起降架次"
    };
    //货运物流
    private static final String[] YSFW_HYWL = new String[]{
            "公路货运量占综合货运量比重","道路货运量","道路货运量同比","道路货运周转量","道路货运周转量同比",
            "成渝通道道路货运量","渝黔桂通道货运量","货运总发送量","货运总周转量","货邮吞吐量"};
    //安全应急
    private static final String[] YSFW_AQYJ = new String[]{
            "船舶滞留数","全市当前道路危货运输安全隐患解除率","全市当前道路危货装载查验率",
            "全市实时道路危货运输驾驶员健康度","全市实时道路危货运输车辆健康度","全市当前道路危货运输安全隐患解除率"};
    //综合执法
    private static final String[] YSFW_ZHZF = new String[]{
            "多跨事件办结率","普通国省干线公路货车超限率","高速公路入口称重货车超限率","巡游出租汽车车辆守法率","巡游出租汽车从业人员守法率",
            "巡游出租汽车单位守法率","交通运输行政处罚案件复议率","交通运输行政处罚案件诉讼率","交通运输行政处罚案件非诉执行率"};
    //行政审批
    private static final String[] YSFW_XZSP = new String[]{
            "一件事一次办办件量","交通政务服务好评率",
            "交通运输信用评价D级企业比率","交通运输信用评价D级从业人员比率", "交通工程建设信用评价D级企业比率","交通工程建设评价D级从业人员比率"};

    //旅客吞吐量
    private static final String[] LKTTL = new String[]{
            "江北机场旅客吞吐量","黔江机场旅客吞吐量","万州机场旅客吞吐量","巫山机场旅客吞吐量","仙女山机场旅客吞吐量"};
    //起降架次
    private static final String[] QJJC = new String[]{
            "江北机场运输起降架次","黔江机场运输起降架次","万州机场运输起降架次","巫山机场运输起降架次","仙女山机场运输起降架次"};
    //货邮吞吐量
    private static final String[] HYTTL = new String[]{
            "江北机场货邮吞吐量","黔江机场货邮吞吐量","万州机场货邮吞吐量","巫山机场货邮吞吐量","仙女山机场货邮吞吐量"};
    @Resource
    private IndustryIndexService industryIndexService;



    public InfrastructureVo infrastructure() {
        InfrastructureVo result = new InfrastructureVo();
        Map<String, IndustryIndexVo> indexVoMap = industryIndexService.getUnRealtime(INFRASTRUCTURE_GL, INFRASTRUCTURE_MH, INFRASTRUCTURE_GH,INFRASTRUCTURE_YZ,INFRASTRUCTURE_TL);
        result.setGls(industryIndexService.getList(indexVoMap, INFRASTRUCTURE_GL));
        result.setMhs(industryIndexService.getList(indexVoMap, INFRASTRUCTURE_MH));
        result.setGhs(industryIndexService.getList(indexVoMap, INFRASTRUCTURE_GH));
        List<IndustryIndexVo> indexVos = industryIndexService.getList(indexVoMap, INFRASTRUCTURE_YZ);

        if (CollUtil.isNotEmpty(indexVos)){
            IndustryIndexVo last = CollUtil.getLast(indexVos);
            last.setIndicatorName(last.getIndicatorName().split("及")[0]);
            last.setIndicatorValue(last.getIndicatorValue().split(",")[0]);
            last.setUnit(last.getUnit().split("/")[0]);
        }
        result.setYzs(indexVos);
        result.setTls(industryIndexService.getList(indexVoMap, INFRASTRUCTURE_TL));
        return result;
    }


    public CoreBusinessRVO coreBusinessRight() {

        CoreBusinessRVO result = new CoreBusinessRVO();
        Map<String, IndustryIndexVo> realtime = industryIndexService.getRealtime(YSFW_KYFW, YSFW_HYWL, YSFW_AQYJ, YSFW_ZHZF, YSFW_XZSP);
        Map<String, IndustryIndexVo> unRealtime = industryIndexService.getUnRealtime(YSFW_KYFW, YSFW_HYWL, YSFW_AQYJ, YSFW_ZHZF, YSFW_XZSP,LKTTL,QJJC,HYTTL);
        realtime.putAll(unRealtime);

        result.setKyfw(industryIndexService.getList(realtime, YSFW_KYFW));
        result.setHywl(industryIndexService.getList(realtime, YSFW_HYWL));
        result.setAqyj(industryIndexService.getList(realtime, YSFW_AQYJ));
        result.setZhzf(industryIndexService.getList(realtime, YSFW_ZHZF));
        result.setXzsp(industryIndexService.getList(realtime, YSFW_XZSP));

        IndustryIndexVo industryIndexVo = new IndustryIndexVo();
        List<IndustryIndexVo> lkttl = industryIndexService.getList(unRealtime, LKTTL);
        BigDecimal lkttlR = IndustryIndexVo.addAll(lkttl);
        industryIndexVo = new IndustryIndexVo("旅客吞吐量",lkttlR.toString(),lkttl.get(0).getUnit());
        result.getKyfw().set(18,industryIndexVo);

        List<IndustryIndexVo> qjjc = industryIndexService.getList(unRealtime, QJJC);
        BigDecimal qjjcR = IndustryIndexVo.addAll(qjjc);
        industryIndexVo = new IndustryIndexVo("起降架次",qjjcR.toString(),qjjc.get(0).getUnit());
        result.getKyfw().set(19,industryIndexVo);

        List<IndustryIndexVo> hyttl = industryIndexService.getList(unRealtime, HYTTL);
        BigDecimal hyttlR = IndustryIndexVo.addAll(hyttl);
        industryIndexVo = new IndustryIndexVo("货邮吞吐量",hyttlR.toString(),hyttl.get(0).getUnit());
        result.getHywl().set(9,industryIndexVo);

        return result;
    }
}
